package com.hairline.hairlinemarket.controller;

import com.github.pagehelper.PageInfo;
import com.hairline.hairlinemarket.bean.MarketUser;
import com.hairline.hairlinemarket.bean.common.BaseRespVo;
import com.hairline.hairlinemarket.bean.vo.OrderVo;
import com.hairline.hairlinemarket.service.OrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Author:杨小凯
 * Date:2023-04-22 17:25
 * Description:<描述>
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/submit")
    public BaseRespVo submit(@RequestBody OrderVo orderVo){

        HashMap<String, Object> map = new HashMap<>();
        // 添加进入order,返回orderId
        Integer orderId = orderService.addOrder(orderVo);
        map.put("grouponLinkId", orderVo.getGrouponLinkId());
        map.put("orderId", orderId);
        return BaseRespVo.ok(map);

    }


    @RequestMapping("/list")
    public BaseRespVo list(Map map){
        // 获取用户
        Subject subject = SecurityUtils.getSubject();
        if (!subject.isAuthenticated()) {
            return BaseRespVo.fail("请登录");
        }
        MarketUser user = (MarketUser) subject.getPrincipal();
        // 查询订单
        PageInfo data = orderService.selectByType(map,user.getId());
        return BaseRespVo.ok();
    }
}
